<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="DialogFormVisibleCom" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="120px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 曲线编号 -->
            <el-form-item label="曲线编号：" prop="cv_code">
              <el-input v-model="formSubmitDataCom.cv_code" v-bind:disabled="dialogStatus==='update'"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 曲线名称 -->
            <el-form-item label="曲线名称：" prop="cv_name">
              <el-input v-model="formSubmitDataCom.cv_name"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="拟合曲线方式" prop="cv_type">
              <el-select
                v-model="formSubmitDataCom.cv_type"
                class="filter-item"
                placeholder="Please select"
                v-bind:disabled="dialogStatus==='update'"
              >
                <el-option v-for="items in curvetypeOptions" :key="items.code" :label="items.name" :value="items.code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 币种 -->
            <el-form-item label="币种" prop="curr_code">
              <el-select v-model="formSubmitDataCom.curr_code" class="filter-item" placeholder="Please select"
                         v-bind:disabled="dialogStatus==='update'">
                <el-option v-for="items in lpOptionscurr" :key="items.curr_code" :label="items.curr_name"
                           :value="items.curr_code"/>
              </el-select>
            </el-form-item>

          </el-col>

          <el-col :span="12">
            <!-- 所属法人 -->
            <el-form-item label="所属法人" prop="lp_code">
              <el-select v-model="formSubmitDataCom.lp_code" class="filter-item" placeholder="Please select"
                         v-bind:disabled="dialogStatus==='update'">
                <el-option v-for="item in lpOptions" :key="item.lp_code" :label="item.lp_name" :value="item.lp_code"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input type="textarea" v-model="formSubmitDataCom.remark" placeholder="Please select"></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    // tableColumn: {
    //     type: Array,
    //     default() {
    //         return []
    //     }
    // },
    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          cv_code: "",
          cv_name: '',
          curr_code: "",
          cv_type: '',
          lp_code: '123456',
          remark: '',
        }
      }
    },
    // 法人selectData
    lpOptions: {
      type: Array
    },
    lpOptionscurr: {
      type: Array
    },
    curvetypeOptions: {
      type: Array
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        cv_code: [{required: true, message: '曲线编号必填', trigger: 'change'}],
        cv_name: [{required: true, message: '曲线名称必填', trigger: 'change'}],
        curr_code: [{required: true, message: '币种必填', trigger: 'change'}],
        lp_code: [{required: true, message: '所属法人必填', trigger: 'change'}],
        cv_type: [{required: true, message: '拟合曲线方式必填', trigger: 'change'}],
      },
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    resetFormData() {
      this.$emit('resetFormDataEmit')
    },
    findlp() {
      this.$refs['datalp'].validate((valid) => {
        if (valid) {
          this.$emit('findlp')
        }
      })
    },
    findcurr() {
      this.$refs['datacurr'].validate((valid) => {
        if (valid) {
          this.$emit('findcurr')
        }
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
        }
      })
    },
    findcurvetype() {
      this.$refs['datacurvetype'].validate((valid) => {
        if (valid) {
          this.$emit('findcurvetype')
          // this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id
          // this.temp.author = 'vue-element-admin'
          // createArticle(this.temp).then(() => {
          //   this.list.unshift(this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Created Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitDataCom, "_XID");
          this.$delete(this.formSubmitDataCom, "lp_name");
          this.$delete(this.formSubmitDataCom, "curr_name");
          const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')

        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>